<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%@ include file="/common/message.jsp"%>
<%
    String orderId = input.getDesc("order_id", "-1");
    Integer uid = token.getUid();
    List<User> users = QBuilder.db("basedb").queryHql("from User where id = " + token.getUid());
    if (isEmpty(users)) {
        msg = new Message(30041, "暂无用户信息");
        Tools.encryptPrint(out, msg);
        return;
    }
    List<Order> orders = QBuilder.db("basedb").select().from("Order").where(new Where("hospital =", hospital).and("status = ", STATUS_ENABLE).and("id =", orderId)).query().getResultObj();
    if (isEmpty(orders)) {
        msg = new Message(30041, "暂无预约信息");
        Tools.encryptPrint(out, msg);
        return;
    }
    User user = users.get(0);
    Integer type = user.getType();
    Order order = orders.get(0);
    order.setState(type == 100 ? 4 : 5);
    DBTools.db("basedb").modItem(order, order.getId());
    if (order.getState() == 5) {
        List<UserProfile> userProfiles = QBuilder.db("basedb").select().from("UserProfile").where(new Where("hospital=", hospital).and("status=", STATUS_ENABLE).and("id=", order.getUid())).query().getResultObj();
        if (!isEmpty(userProfiles)) {
            uid = userProfiles.get(0).getUid();
        }
    }
    createMsg(order, uid);
    Tools.encryptPrint(out, msg);
%>
